const express = require('express')

const app = express()

// 使用referer内容进行判断
function guardAgainst(req,res,next){
    let referer = req.get('referer')
    if(referer){
        let url = new URL(referer)
        let hostname = url.hostname
        console.log(hostname);

        if(hostname !== '127.0.0.1'){
            res.status(404).send('<p>404 not found</p>');
            return;
        }
    }
    next()
}

app.use(guardAgainst)

app.use(express.static(__dirname + '/public'))

app.listen(3000,()=>{
    console.log('3000服务已启动');
})
